from flask import Flask, request,json,send_file
from flask.json import jsonify
from flask_cors import CORS
# from werkzeug.utils import secure_filename

import os

from service.Message import Message,CodeMessageData
from domain.domain import *
from dao.userDAODir.UserDAO import UserDAO
from dao.tableDAODir.PersonalTeamDAO import PersonalTeamDAO
from dao.tableDAODir.ExchangeDAO import ExchangeDAO
from dao.tableDAODir.TeachingScienceDAO import TeachingScienceDAO
from dao.tableDAODir.BookDAO import BookDAO
from dao.tableDAODir.PaperDAO import PaperDAO
from dao.tableDAODir.PatentDAO import PatentDAO
from dao.tableDAODir.ProjectDAO import ProjectDAO
from dao.tableDAODir.SubjectDAO import SubjectDAO
from dao.tableDAODir.FileDAO import FileDAO


from service.Transfer import Transfer
from helper.TokenHelper import TokenHelper
from service.DataChange import DataChange

from helper.ConnectionHelper import ConnectionHelper
from helper.XlsHelper import XlsHelper
from helper.FileHelper import FileHelper


connectionHelper=ConnectionHelper()
xlsHelper=XlsHelper()
fileHelper=FileHelper()
session,engine=connectionHelper.getSessionAndEngine()

userDao=UserDAO()
personalTeamDao=PersonalTeamDAO()
bookDao=BookDAO()
exchangeDao=ExchangeDAO()
teachingScienceDao=TeachingScienceDAO()
paperDao=PaperDAO()
patentDao=PatentDAO()
projectDao=ProjectDAO()
subjectDao=SubjectDAO()
fileDao=FileDAO()


transfer=Transfer()
tokenHelper=TokenHelper()
# token="529eaa1f1acc8874032669065899a1c5ff242d52b676ca57f8abd6c6834e04d4"
# tokenHelper.addToken(token,1,1)
# tokenHelper.addToken("4665b2c88953faae8d73d7aca016273a88b13824cf993a81435fa7d84ab90e07","2017",1)
# tokenHelper.addToken("529eaa1f1acc8874032669065899a1c5ff242d52b676ca57f8abd6c6834e04d4","2019",1)
# tokenHelper.addToken("7c597a9de4501bc0fb1e1f1b6b7b2ac1b456027506a5f58978059f0ac899243f","2022",3)
dataChange=DataChange()
app = Flask(__name__)
app.config['uploadDir']=xlsHelper.uploadDir
app.config['downloadDir']=xlsHelper.downloadDir


CORS(app)

# # 跨域支持
# def after_request(resp):
#     resp.headers['Access-Control-Allow-Origin'] = '*'
#     return resp
#
# app.after_request(after_request)



@app.route('/')
def helloWorld():
    test={}
    test[43434]=433434
    return test




#用户登录
@app.route("/user/login",methods=["POST","GET"])
def userLogin():
    returnResult ={}
    if(request.method=='POST'):
        userData=json.loads(request.data)
        # userData=request.form
        job_number=userData['job_number']
        password=userData['password']
        result=userDao.getPAIdByJobNumber(session, job_number)
        token = ""
        if(result.code!=0000):#该账号不存在
            returnResult=result.webReturnCodeMessage()
        else:
            if(password==result.data[0]):
                code=0000
                token=transfer.SHA256(job_number,password)
                tokenHelper.addToken(token,job_number,result.data[1:])
            else:
                code=1002
            returnResult=Message(code, CodeMessageData[code]).webReturnCodeMessage()
            returnResult['token'] = token
            returnResult['accessLevel']=result.data[1]
        return returnResult
    else:
        code=2002
        return Message(code,CodeMessageData[code]).webReturnCodeMessage()

#用户注销
@app.route("/user/loginOut",methods=["POST","GET"])
def userLoginOut():
    returnResult = {}
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):
            code = judge.code
        else:
            code=tokenHelper.deleteToken(token).code
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()

#添加用户
@app.route("/user/add",methods=["POST","GET"])
def userAdd():
    returnResult = {}
    if (request.method == 'POST'):
        data=json.loads(request.data)
        token=data['token']
        judge=tokenHelper.verifyToken(token)
        if(judge.code!=0000):
            code=judge.code
        else:
            privilegeResult=tokenHelper.verifyAdmin(token)
            if privilegeResult.code==0000:
                result = dataChange.userDataChange(data['data'],changeType=1)
                if (result.code != 0000):
                    code = 2003
                else:
                    newResult = userDao.addAll(session, result.data)
                    code = newResult.code
            else:
                code=privilegeResult.code
    else:#请求方式错误
        code=2002
    return Message(code,CodeMessageData[code]).webReturnCodeMessage()



#删除用户
#未考虑管理员删除自己的密码
@app.route("/user/delete",methods=["POST","GET"])
def userDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000): #token不可用
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            if privilegeResult.code == 0000:
                idList=data['data']
                result=userDao.deleteByIdlist(session,idList)
                code = result.code
                if(code==0000):
                    tokenResult = tokenHelper.deleteTokenByIdList(idList)
                    code=tokenResult.code
                    if(code!=0000):
                        code=1025
            else:
                code=privilegeResult.code
    else:#请求方式错误
        code=2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#用户数据更新
#未考虑管理员修改自己的密码
@app.route("/user/update",methods=["POST","GET"])
def userUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):#验证token
            code = judge.code
        else:
            result = dataChange.userDataChange(data['data'],idFlag=1,changeType=1)
            if (result.code != 0000):#数据转换
                code = 2003
            else:
                privilegeResult = tokenHelper.verifyAdmin(token)
                if privilegeResult.code == 0000:
                    newResult = userDao.updateByDataList(session, result.data)
                    code=newResult.code
                else:
                    code=privilegeResult.code
                    jobNumber=tokenHelper.getJobNumberBytoken(token)
                    privilege=tokenHelper.getPrivilege(token)
                    oneData=result.data[0]
                    if(oneData.job_number==jobNumber and oneData.access_level==privilege):
                        newResult = userDao.updateByDataList(session, [oneData])
                        code=newResult.code
                        if(code==0000):
                            newToken=transfer.SHA256(oneData.job_number,oneData.password)
                            tokenResult=tokenHelper.updateToken(token,newToken,oneData.job_number,oneData.access_level)
                            code=tokenResult.code
                            if(code==0000):
                                return Message(code, "修改成功，请重新登录").webReturnCodeMessage()
                            else:
                                code=1032
                    else:
                        code=1024
                # code = newResult.code
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#用户数据更新
#未考虑管理员修改自己的密码
@app.route("/user/changePassword",methods=["POST","GET"])
def userChangePassword():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):#验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            jobNumber=data["job_number"]
            if privilegeResult.code == 0000: #超级管理员
                userInfo=userDao.getOneInfoByJobNumber(session,jobNumber)
                if (userInfo.code == 0000):
                    userData=userInfo.data[0]
                    userData.password = data['password']
                    code = userDao.update(session, userData).code
                    if(code == 0000):
                        # 密码更新之后，删除token
                        code=tokenHelper.deleteTokenByJobNumber(jobNumber).code
                else:
                    code = 1071
                result = Message(code, CodeMessageData[code])
            else:  #非超级管理员
                selfJobNumber = tokenHelper.getJobNumberBytoken(token)
                #验证账号
                if(selfJobNumber==jobNumber):
                    code=0000
                    userInfo = userDao.getOneInfoByJobNumber(session, jobNumber)
                    #验证账号是否存在，比较出现自己账号被删除的情况
                    if(userInfo.code==0000):
                        userData = userInfo.data[0]
                        userData.password = data['password']
                        code = userDao.update(session, userData).code
                        if (code == 0000):
                            #密码更新之后，删除token
                            code = tokenHelper.deleteTokenByJobNumber(jobNumber).code
                    else:
                        code=1071
                #账号不存在
                else:
                    code=1070
                result=Message(code,CodeMessageData[code])
            return  result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



















#用户查询
@app.route("/user/search",methods=["POST","GET"])
def userSearch():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = userDao.getAllInfo(session)
                return result.webReturnAllJson()
            else:
                code=privilegeResult.code
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()












#著作教材
@app.route("/book",methods=["POST","GET"])
def book():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber=tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = bookDao.getAllInfo(session, jobNumber,DHFlag=1)
            else:
                result = bookDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/book/add",methods=["POST","GET"])
def bookAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)

        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if(privilegeResult.code==0000):
                code=1026
            else:
                allData = dataChange.bookDataChange(data['data'],jobNumberJudge=[number])
                if(allData.code!=0000):
                    return allData.webReturnCodeMessage()
                result = bookDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/book/delete",methods=["POST","GET"])
def bookDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber=tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = bookDao.deleteByJobNumberAndIdlist(session, jobNumber, idList, adminFlag=1)
            else:
                result = bookDao.deleteByJobNumberAndIdlist(session, jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/book/update",methods=["POST","GET"])
def bookUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.bookDataChange(data['data'], idFlag=1)
            if (privilegeResult.code == 0000):
                result = bookDao.updateByJobNumberAndDataList(session,jobNumber, allData.data,adminFlag=1)
            else:
                result = bookDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()























#培训进修、交流
@app.route("/exchange",methods=["POST","GET"])
def exchange():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = exchangeDao.getAllInfo(session,jobNumber,DHFlag=1)
            else:
                result = exchangeDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/exchange/add",methods=["POST","GET"])
def exchangeAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.exchangeDataChange(data['data'],jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = exchangeDao.addAll(session, allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/exchange/delete",methods=["POST","GET"])
def exchangeDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = exchangeDao.deleteByJobNumberAndIdlist(session, jobNumber,idList,adminFlag=1)
            else:
                result = exchangeDao.deleteByJobNumberAndIdlist(session, jobNumber,idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/exchange/update",methods=["POST","GET"])
def exchangeUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.exchangeDataChange(data['data'],  idFlag=1)
            if (privilegeResult.code == 0000):
                result = exchangeDao.updateByJobNumberAndDataList(session,jobNumber, allData.data,adminFlag=1)
            else:
                result = exchangeDao.updateByJobNumberAndDataList(session, jobNumber,allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


























# 教学科研学奖
@app.route("/naturalscience",methods=["POST","GET"])
def teachingscience():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = teachingScienceDao.getAllInfo(session, jobNumber, DHFlag=1)
            else:
                result = teachingScienceDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/naturalscience/add",methods=["POST","GET"])
def teachingscienceAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.teachingScienceChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = teachingScienceDao.addAll(session, allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/naturalscience/delete",methods=["POST","GET"])
def teachingscienceDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = teachingScienceDao.deleteByJobNumberAndIdlist(session, jobNumber, idList, adminFlag=1)
            else:
                result = teachingScienceDao.deleteByJobNumberAndIdlist(session, jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/naturalscience/update",methods=["POST","GET"])
def teachingscienceUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.teachingScienceChange(data['data'], idFlag=1)
            if (privilegeResult.code == 0000):
                result = teachingScienceDao.updateByJobNumberAndDataList(session, jobNumber, allData.data, adminFlag=1)
            else:
                result = teachingScienceDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


















# 论文
@app.route("/paper",methods=["POST","GET"])
def paper():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = paperDao.getAllInfo(session, jobNumber,DHFlag=1)
            else:
                result = paperDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/paper/add",methods=["POST","GET"])
def paperAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.paperDataChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = paperDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/paper/delete",methods=["POST","GET"])
def paperDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            print(idList)
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = paperDao.deleteByJobNumberAndIdlist(session,jobNumber, idList,adminFlag=1)
            else:
                result = paperDao.deleteByJobNumberAndIdlist(session,jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/paper/update",methods=["POST","GET"])
def paperUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.paperDataChange(data['data'], idFlag=1,jobNumberJudge= [jobNumber])
            if (privilegeResult.code == 0000):
                result = paperDao.updateByJobNumberAndDataList(session, jobNumber,allData.data,adminFlag=1)
            else:
                result = paperDao.updateByJobNumberAndDataList(session, jobNumber,allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()
















# 专利
@app.route("/patent",methods=["POST","GET"])
def patent():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = patentDao.getAllInfo(session, jobNumber,DHFlag=1)
            else:
                result = patentDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/patent/add",methods=["POST","GET"])
def patentAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.patentDataChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = patentDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/patent/delete",methods=["POST","GET"])
def patentDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = patentDao.deleteByJobNumberAndIdlist(session, jobNumber,idList,adminFlag=1)
            else:
                result = patentDao.deleteByJobNumberAndIdlist(session, jobNumber,idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/patent/update",methods=["POST","GET"])
def patentUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.patentDataChange(data['data'],idFlag=1,jobNumberJudge=[jobNumber] )
            if (privilegeResult.code == 0000):
                result = patentDao.updateByJobNumberAndDataList(session, jobNumber, allData.data,adminFlag=1)
            else:
                result = patentDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()




















#个人或团队荣誉
@app.route("/personalteam",methods=["POST","GET"])
def personalteam():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = personalTeamDao.getAllInfo(session,  jobNumber,DHFlag=1)
            else:
                result = personalTeamDao.getAllInfo(session,  jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/personalteam/add",methods=["POST","GET"])
def personalteamAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.personalTeamDataChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = personalTeamDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()

#通过id删除
@app.route("/personalteam/delete",methods=["POST","GET"])
def personalteamDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = personalTeamDao.deleteByJobNumberAndIdlist(session,  jobNumber, idList, adminFlag=1)
            else:
                result = personalTeamDao.deleteByJobNumberAndIdlist(session,  jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#更新数据
@app.route("/personalteam/update",methods=["POST","GET"])
def personalteamUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.personalTeamDataChange(data['data'], jobNumber, idFlag=1)
            if (privilegeResult.code == 0000):
                result = personalTeamDao.updateByJobNumberAndDataList(session, jobNumber, allData.data,adminFlag=1)
            else:
                result = personalTeamDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()
























#项目
@app.route("/project",methods=["POST","GET"])
def project():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = projectDao.getAllInfo(session, jobNumber,DHFlag=1)
            else:
                result=bookDao.getAllInfo(session,jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/project/add",methods=["POST","GET"])
def projectAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.projectDataChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = projectDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/project/delete",methods=["POST","GET"])
def projectDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = projectDao.deleteByJobNumberAndIdlist(session, jobNumber, idList,adminFlag=1)
            else:
                result = projectDao.deleteByJobNumberAndIdlist(session, jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/project/update",methods=["POST","GET"])
def projectUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.projectDataChange(data['data'], jobNumber, idFlag=1)
            if (privilegeResult.code == 0000):
                result = projectDao.updateByJobNumberAndDataList(session, jobNumber, allData.data,adminFlag=1)
            else:
                result = projectDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()







#学科竞赛
@app.route("/subject",methods=["POST","GET"])
def subject():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            if privilegeResult.code == 0000:
                result = subjectDao.getAllInfo(session,jobNumber,DHFlag=1)
            else:
                result = subjectDao.getAllInfo(session, jobNumber)
            return result.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#增加数据
@app.route("/subject/add",methods=["POST","GET"])
def subjectAdd():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            privilegeResult = tokenHelper.verifyAdmin(token)
            number = tokenHelper.getJobNumberBytoken(token)
            if (privilegeResult.code == 0000):
                code = 1026
            else:
                allData = dataChange.subjectDataChange(data['data'], jobNumberJudge=[number])
                if (allData.code != 0000):
                    return allData.webReturnCodeMessage()
                result = subjectDao.addAll(session,allData.data)
                return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()


#通过id删除
@app.route("/subject/delete",methods=["POST","GET"])
def subjectDelete():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            idList=data['data']
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            if (privilegeResult.code == 0000):
                result = subjectDao.deleteByJobNumberAndIdlist(session,  jobNumber, idList, adminFlag=1)
            else:
                result = subjectDao.deleteByJobNumberAndIdlist(session,  jobNumber, idList)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#更新数据
@app.route("/subject/update",methods=["POST","GET"])
def subjectUpdate():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            allData = dataChange.subjectDataChange(data['data'], jobNumber, idFlag=1)
            if (privilegeResult.code == 0000):
                result = subjectDao.updateByJobNumberAndDataList(session,jobNumber, allData.data,adminFlag=1)
            else:
                result = subjectDao.updateByJobNumberAndDataList(session, jobNumber, allData.data)
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()



#上传表格
@app.route("/excel/upload",methods=["POST","GET"])
def excelUpload():
    if (request.method == 'POST'):
        form=request.form
        token = form['token']
        excelType=int(form['type'])
        try:
            if(len(form['list'])):
                filedList = form['list'][1:-1].replace("'", "").replace(" ", "").split(",")
            else:
                filedList=[]
        except:
            filedList=[]
        file=request.files['file']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            if(excelType<0 and excelType>8):
                code = 2005
                result = Message(code, CodeMessageData[code])
            # filename = secure_filename(file.filename)
            fileName =xlsHelper.getNameByExcelType(excelType)
            savePath = os.path.join(app.config['uploadDir'], fileName)
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyAdmin(token)
            code = privilegeResult.code
            if (code == 0000 and excelType==0) or (code!=0000 and excelType in [ i for i in range(0,9)]):
                pass
            else:
                if(code==0000):
                    code = 1026
                else:
                    code= 1027
                return Message(code, CodeMessageData[code]).webReturnAllJson()
            file.save(savePath)
            sheet = xlsHelper.openXls(savePath)
            excelData = xlsHelper.readAllDataByType(sheet, excelType, filedList)
            #避免表格数据错误
            if excelData.code==0000:
                code=0000
                dicAllData = excelData.data
                result = Message(code, CodeMessageData[code])
                # print(dicAllData)
                userId = tokenHelper.getJobNumberBytoken(token)
                if (excelType == 0):
                    allData = dataChange.userDataChange(dicAllData[1:], changeType=1)
                    result = userDao.addAll(session, allData.data)
                elif (excelType == 1):
                    allData = dataChange.personalTeamDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = personalTeamDao.addAll(session, allData.data)
                elif (excelType == 2):
                    allData = dataChange.exchangeDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = exchangeDao.addAll(session, allData.data)
                elif (excelType == 3):
                    allData = dataChange.subjectDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = subjectDao.addAll(session, allData.data)
                elif (excelType == 4):
                    allData = dataChange.projectDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = projectDao.addAll(session, allData.data)
                elif (excelType == 5):
                    allData = dataChange.teachingScienceChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = teachingScienceDao.addAll(session, allData.data)
                elif (excelType == 6):
                    allData = dataChange.patentDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = patentDao.addAll(session, allData.data)
                elif (excelType == 7):
                    allData = dataChange.paperDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = paperDao.addAll(session, allData.data)
                elif (excelType == 8):
                    allData = dataChange.bookDataChange(dicAllData[1:], jobNumberJudge=[userId])
                    result = bookDao.addAll(session, allData.data)
            else:
                code=excelData.code
                result=Message(code,CodeMessageData[code])
            return result.webReturnCodeMessage()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()

#下载表格
@app.route("/excel/download/all",methods=["POST","GET"])
def excelDownloadAll():
    if (request.method == 'POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            code=judge.code
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            excelType=data['type']
            if (excelType > -1 and excelType < 9):
                # print(dicAllData)
                result = Message(code, CodeMessageData[code], [])
                userId = tokenHelper.getJobNumberBytoken(token)
                privilegeResult = tokenHelper.verifyDH(token)
                code = privilegeResult.code
                if code != 0000 and excelType == 0:
                    code = 1029
                    return Message(code, CodeMessageData[code]).webReturnAllJson()
                if code==0000:
                    flag = int(data['flag'])
                else:
                    flag=0
                if (excelType == 0):
                    result = userDao.getAllInfo(session)
                elif (excelType == 1):
                    result = personalTeamDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 2):
                    result = exchangeDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 3):
                    result = subjectDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 4):
                    result = projectDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 5):
                    result = teachingScienceDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 6):
                    result = patentDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 7):
                    result = paperDao.getAllInfo(session, userId, DHFlag=flag)
                elif (excelType == 8):
                    result = bookDao.getAllInfo(session, userId, DHFlag=flag)
                tableName = xlsHelper.getNameByExcelType(excelType)
                saveDir = app.config["downloadDir"]
                returnResult = xlsHelper.writeXlsByType(result.data, saveDir, tableName, excelType)
            else:
                code = 2005
                returnResult = Message(code, CodeMessageData[code])
            return returnResult.webReturnAllJson()
    else:  # 请求方式错误
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnAllJson()



@app.route("/excel/download/part",methods=["POST","GET"])
def excelDownloadPart():
    if(request.method=='POST'):
        data = json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            code = judge.code
            jobNumber = tokenHelper.getJobNumberBytoken(token)
            privilegeResult = tokenHelper.verifyDH(token)
            excelType = data['type']
            excelType=excelType
            flag = 1
            idList=data['idList']
            result=Message(code,CodeMessageData[code])
            if(privilegeResult.code==0000 and (excelType>-1 and excelType<9)):
                if (excelType == 0):
                    result = userDao.getDataByIdList(session,idList)
            elif(privilegeResult.code!=0000 and (excelType>0 and excelType<9)):
                flag=0
            else:
                code=2006
            if(code!=2006):
                if (excelType == 1):
                    result = personalTeamDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                elif (excelType == 2):
                    result = exchangeDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                elif (excelType == 3):
                    result = subjectDao.getDataByJobNumberAndIdList(session, jobNumber, idList,flag)
                elif (excelType == 4):
                    result = projectDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                elif (excelType == 5):
                    result = teachingScienceDao.getDataByJobNumberAndIdList(session, jobNumber, idList, flag)
                elif (excelType == 6):
                    result = patentDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                elif (excelType == 7):
                    result = paperDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                if (excelType == 8):
                    result = bookDao.getDataByJobNumberAndIdList(session, jobNumber,idList, flag)
                excelData=result.data
                if(len(excelData)==0):
                    code=2007
                else:
                    tableName=xlsHelper.getNameByExcelType(excelType)
                    saveDir = app.config["downloadDir"]
                    returnResult = xlsHelper.writeXlsByType(result.data, saveDir, tableName, excelType)
                    return returnResult.webReturnAllJson()
    else:
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnAllJson()







#文件上传
@app.route("/file/upload",methods=['POST',"GET"])
def fileUpload():
    if (request.method == 'POST'):
        form=request.form
        token = form['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            code = 0000
            privilegeResult = tokenHelper.verifyAdmin(token)
            if(privilegeResult.code==0000):
                code=1038
            else:
                jobNumber = tokenHelper.getJobNumberBytoken(token)
                year=form['year']
                excelType=int(form['excel_type'])
                id=form['id']
                if(excelType<0 and excelType>9):
                    code=2005
                    return  Message(code,CodeMessageData[code])
                if (excelType == 1):
                    result = personalTeamDao.getName(session,id)
                elif (excelType == 2):
                    result = exchangeDao.getName(session,id)
                elif (excelType == 3):
                    result = subjectDao.getName(session,id)
                elif (excelType == 4):
                    result = projectDao.getName(session,id)
                elif (excelType == 5):
                    result = teachingScienceDao.getName(session,id)
                elif (excelType == 6):
                    result = patentDao.getName(session,id)
                elif (excelType == 7):
                    result = paperDao.getName(session,id)
                # elif (excelType == 8):
                else:
                    result = bookDao.getName(session,id)
                if(code==0000):
                    file = request.files['file']
                    try:
                        typeList = file.filename.split('.')
                        saveType="."+".".join([ str(one) for one in typeList[1:]])
                    except:
                        code=2009
                        return Message(code,CodeMessageData[code]).webReturnCodeMessage()
                    # tableEngName=fileHelper.getEngName(excelType)
                    nameList=[jobNumber,year,excelType,result.data[0]]
                    result=fileHelper.getName(nameList,saveType)
                    code = result.code
                    if(result.code==0000):
                        name = result.data[0]
                        pathList = [fileHelper.getFileSaveDir(), year, jobNumber, excelType]
                        saveDir = fileHelper.getPath(pathList)
                        result = fileHelper.makedirs(saveDir)
                        if (result.code == 0000):
                            code = 0000
                            path=fileHelper.getPath([saveDir,name])
                            code=fileHelper.remove(path).code
                            if(code==0000):
                                try:
                                    file.save(path)
                                    typeFileId = fileHelper.typeFileId(excelType,id)
                                    newFileData = [jobNumber, year, excelType, typeFileId, name]
                                    result = dataChange.fileDataChange(newFileData)
                                    code=result.code
                                    if(code==0000):
                                        fileObj = result.data[0]
                                        findFileData=fileDao.getInfoByTypeFileId(session,typeFileId)
                                        if(findFileData.code!=0000):
                                            #文件未上传过
                                            result = fileDao.add(session, fileObj)
                                            code = result.code
                                        else:
                                            oldObj=findFileData.data[0]
                                            if(oldObj.file_name!=fileObj.file_name):
                                                path = fileHelper.getPath([saveDir, oldObj.file_name])
                                                code = fileHelper.remove(path).code
                                                if(code==0000):
                                                    result = fileDao.update(session, fileObj)
                                                    code = result.code
                                            else:
                                                result = fileDao.update(session, fileObj)
                                                code = result.code
                                except:
                                    code = 1036

                        else:
                            code = 1034
                else:
                    code=1035
    else:
        code = 2002
    return Message(code, CodeMessageData[code]).webReturnCodeMessage()





@app.route("/file/download",methods=['POST',"GET"])
def downloadFile():
    if (request.method == 'GET'):
        data = request.args
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            code = 0000
            privilegeResult = tokenHelper.verifyDH(token)
            if(privilegeResult.code==0000):
                excelType = data['excel_type']
                id=data['id']
                typeFileId=fileHelper.typeFileId(excelType,id)
                result=fileDao.getInfoByTypeFileId(session,typeFileId)
                code=result.code
                if(code==0000):
                    fileData=result.data[0]
                    pathList=[fileHelper.getFileSaveDir(),fileData.year,fileData.job_number,fileData.excel_type,fileData.file_name]
                    filePath=fileHelper.getPath(pathList)
                    if os.path.exists(filePath):
                        return send_file(filePath, as_attachment=True)
                    else:
                        code=1052
            else:
                code=1050
    else:
        data =json.loads(request.data)
        token = data['token']
        judge = tokenHelper.verifyToken(token)
        if (judge.code != 0000):  # 验证token
            code = judge.code
        else:
            code = 0000
            privilegeResult = tokenHelper.verifyDH(token)
            if (privilegeResult.code == 0000):
                excelType = data['excel_type']
                id = data['id']
                typeFileId = fileHelper.typeFileId(excelType, id)
                result = fileDao.getInfoByTypeFileId(session, typeFileId)
                code = result.code
                if (code == 0000):
                    fileData = result.data[0]
                    pathList = [fileHelper.getFileSaveDir(), fileData.year, fileData.job_number, fileData.excel_type,
                                fileData.file_name]
                    filePath = fileHelper.getPath(pathList)
                    if os.path.exists(filePath):
                        return send_file(filePath, as_attachment=True)
                    else:
                        code = 1052
            else:
                code = 1050

    return Message(code, CodeMessageData[code]).webReturnCodeMessage()







@app.route('/hello')
def hello():
    return jsonify({'hello':'world'})




if __name__ == '__main__':
    app.run(threaded=True)
    #app.run(processes=True)
    # Production
    #http_server = WSGIServer(('', 5000), app)
    #http_server.serve_forever()